/*
 *  蓝桥杯2020 国赛 贪心 答疑
 * */

#include <iostream>
#include <algorithm>

using namespace std;

struct Student {
	long long zi; // 所花费的总时间
	long long di; // 进门和答疑的时间总和
} student[1010];

int main() {
	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		int si, ai, ei;
		cin >> si >> ai >> ei;
		student[i].zi = si + ai + ei;
		student[i].di = si + ai;
	}

	sort(student, student + n, [](const Student& s1, const Student& s2) {
		return s1.zi != s2.zi ? s1.zi < s2.zi : s1.di < s2.di;
	});

	long long sum = 0, p = 0;
	for (int i = 0; i < n; ++i) {
		sum += student[i].di + p;
		p += student[i].zi;
	}

	cout << sum << endl;

	return 0;
}
